#include "Compiler.hpp"
#include "Runner.hpp"
#include "Compile_run.hpp"
#include "../Comm/httplib.h"
using namespace httplib;
using namespace ns_com_run;
void Usage(std::string process)
{
    std::cerr<<process<<" port"<<"\n";

}
int main(int argc,char*argv[])
{
    if(argc!=2)
    {
        Usage(argv[0]);
        return 1;
    }
    Server srv;
    srv.Get("/hello", [](const Request &req, Response &resp)
            {
                resp.set_content("hello world,你好世界", "text/plain;charset=utf-8");
            });
    srv.Post("/compile_and_run", [](const Request &req, Response &resp)
       {
        std::string in_json=req.body;
        std::string out_json;
        if(!in_json.empty())
        {
            Compile_Run::Start(in_json,&out_json);
            resp.set_content(out_json,"application/json;charset=utf-8");
        } });
    // srv.set_base_dir("./wwwroot");
    srv.listen("0.0.0.0", atoi(argv[1]));
    // Compiler com;
    // std::string code="code";
    // com.Compile(code);
    // int n=Runner::Run(code,1,20);
    //  in_json{"code":"#include..","input":"...","cpu_limit":"","mem_limit":""};
    //  out_json{"status":"0","reason":"","stdout":"","stderr":""}
    // Json::Value value;
    // value["code"]=R"(#include<iostream>
    // int main()
    // {

    // std::cout<<"你好看见你了"<<std::endl;

    // return 0;
    // })";
    // value["input"]="";
    // value["cpu_limit"]=1;
    // value["mem_limit"]=10240*3;

    // std::string in_json;
    // Json::FastWriter write;
    // in_json=write.write(value);//返回一个序列化函数
    // //std::cout<<in_json<<std::endl;
    // std::string out_json;
    // Compile_Run::Start(in_json,&out_json);
    // std::cout<<out_json<<std::endl;
    return 0;
}